package collection;

import day04.WhileDemo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericDemo {
    public static void main(String[] args) {
        Collection<Point> c =new ArrayList<>();
        c.add(new Point(1,2));//因为每次添加一个新的对象，引用就直接new Point（参数）
        c.add(new Point(3,4));
        c.add(new Point(5,6));
        c.add(new Point(7,8));
        c.add(new Point(9,0));

        Iterator<Point>  it =c.iterator();
        while(it.hasNext()){
            Point p =it.next();//接收的类型和集合元素类型一样，所以不需要强转
            System.out.println(p);
        }








      /*  Collection<String> c =new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");


        Iterator<String> it =c.iterator();
        while(it.hasNext()){
            String str = it.next();//本身是String，所以不用强转了
        }

        for (String str:c){
            System.out.println(str);
        }*/
    }
}
